home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 November / CPNL0711.ISO / boekhoud / finan / BADGER finance v1.0 beta 2.exe / xampplite / phpMyAdmin / export.php < prev    next >
PHP Script  |  2006-04-13  |  25KB  |  675 lines

  1. <?php
  2. /* $Id: export.php,v 2.38.2.2 2006/04/14 09:45:23 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * Get the variables sent or posted to this script and a core script
  7.  */
  8. require_once('./libraries/common.lib.php');
  9. require_once('./libraries/zip.lib.php');
  10.  
  11. PMA_checkParameters(array('what', 'export_type'));
  12.  
  13. // What type of export are we doing?
  14. if ($what == 'excel') {
  15.     $type = 'csv';
  16. } else {
  17.     $type = $what;
  18. }
  19.  
  20. // Get the functions specific to the export type
  21. require('./libraries/export/' . PMA_securePath($type) . '.php');
  22.  
  23. // Generate error url
  24. if ($export_type == 'server') {
  25.     $err_url = 'server_export.php?' . PMA_generate_common_url();
  26. } elseif ($export_type == 'database' && isset($db) && strlen($db)) {
  27.     $err_url = 'db_details_export.php?' . PMA_generate_common_url($db);
  28. } elseif ($export_type == 'table' && isset($db) && strlen($db) && isset($table) && strlen($table)) {
  29.     $err_url = 'tbl_properties_export.php?' . PMA_generate_common_url($db, $table);
  30. } else {
  31.     die('Bad parameters!');
  32. }
  33.  
  34. /**
  35.  * Increase time limit for script execution and initializes some variables
  36.  */
  37. @set_time_limit($cfg['ExecTimeLimit']);
  38. if (!empty($cfg['MemoryLimit'])) {
  39.     @ini_set('memory_limit', $cfg['MemoryLimit']);
  40. }
  41.  
  42. // Start with empty buffer
  43. $dump_buffer = '';
  44. $dump_buffer_len = 0;
  45.  
  46. // We send fake headers to avoid browser timeout when buffering
  47. $time_start = time();
  48.  
  49.  
  50. /**
  51.  * Output handler for all exports, if needed buffering, it stores data into
  52.  * $dump_buffer, otherwise it prints thems out.
  53.  *
  54.  * @param   string  the insert statement
  55.  *
  56.  * @return  bool    Whether output suceeded
  57.  */
  58. function PMA_exportOutputHandler($line)
  59. {
  60.     global $time_start, $dump_buffer, $dump_buffer_len, $save_filename;
  61.  
  62.     // Kanji encoding convert feature
  63.     if ($GLOBALS['output_kanji_conversion']) {
  64.         $line = PMA_kanji_str_conv($line, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : '');
  65.     }
  66.     // If we have to buffer data, we will perform everything at once at the end
  67.     if ($GLOBALS['buffer_needed']) {
  68.  
  69.         $dump_buffer .= $line;
  70.         if ($GLOBALS['onfly_compression']) {
  71.  
  72.             $dump_buffer_len += strlen($line);
  73.  
  74.             if ($dump_buffer_len > $GLOBALS['memory_limit']) {
  75.                 if ($GLOBALS['output_charset_conversion']) {
  76.                     $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer);
  77.                 }
  78.                 // as bzipped
  79.                 if ($GLOBALS['compression'] == 'bzip'  && @function_exists('bzcompress')) {
  80.                     $dump_buffer = bzcompress($dump_buffer);
  81.                 }
  82.                 // as a gzipped file
  83.                 elseif ($GLOBALS['compression'] == 'gzip' && @function_exists('gzencode')) {
  84.                     // without the optional parameter level because it bug
  85.                     $dump_buffer = gzencode($dump_buffer);
  86.                 }
  87.                 if ($GLOBALS['save_on_server']) {
  88.                     $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer);
  89.                     if (!$write_result || ($write_result != strlen($dump_buffer))) {
  90.                         $GLOBALS['message'] = sprintf($GLOBALS['strNoSpace'], htmlspecialchars($save_filename));
  91.                         $GLOBALS['show_error_header'] = TRUE;
  92.                         return FALSE;
  93.                     }
  94.                 } else {
  95.                     echo $dump_buffer;
  96.                 }
  97.                 $dump_buffer = '';
  98.                 $dump_buffer_len = 0;
  99.             }
  100.         } else {
  101.             $time_now = time();
  102.             if ($time_start >= $time_now + 30) {
  103.                 $time_start = $time_now;
  104.                 header('X-pmaPing: Pong');
  105.             } // end if
  106.         }
  107.     } else {
  108.         if ($GLOBALS['asfile']) {
  109.             if ($GLOBALS['save_on_server'] && strlen($line) > 0) {
  110.                 $write_result = @fwrite($GLOBALS['file_handle'], $line);
  111.                 if (!$write_result || ($write_result != strlen($line))) {
  112.                     $GLOBALS['message'] = sprintf($GLOBALS['strNoSpace'], htmlspecialchars($save_filename));
  113.                     $GLOBALS['show_error_header'] = TRUE;
  114.                     return FALSE;
  115.                 }
  116.                 $time_now = time();
  117.                 if ($time_start >= $time_now + 30) {
  118.                     $time_start = $time_now;
  119.                     header('X-pmaPing: Pong');
  120.                 } // end if
  121.             } else {
  122.                 // We export as file - output normally
  123.                 if ($GLOBALS['output_charset_conversion']) {
  124.                     $line = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $line);
  125.                 }
  126.                 echo $line;
  127.             }
  128.         } else {
  129.             // We export as html - replace special chars
  130.             echo htmlspecialchars($line);
  131.         }
  132.     }
  133.     return TRUE;
  134. } // end of the 'PMA_exportOutputHandler()' function
  135.  
  136. // Will we save dump on server?
  137. $save_on_server = isset($cfg['SaveDir']) && !empty($cfg['SaveDir']) && !empty($onserver);
  138.  
  139. // Ensure compressed formats are associated with the download feature
  140. if (empty($asfile)) {
  141.     if ($save_on_server) {
  142.         $asfile = TRUE;
  143.     } elseif (isset($compression) && ($compression == 'zip' | $compression == 'gzip' | $compression == 'bzip')) {
  144.         $asfile = TRUE;
  145.     } else {
  146.         $asfile = FALSE;
  147.     }
  148. } else {
  149.     $asfile = TRUE;
  150. }
  151.  
  152. // Defines the default <CR><LF> format. For SQL always use \n as MySQL wants this on all platforms.
  153. if ($what == 'sql') {
  154.     $crlf = "\n";
  155. } else {
  156.     $crlf = PMA_whichCrlf();
  157. }
  158.  
  159. $output_kanji_conversion = function_exists('PMA_kanji_str_conv') && $type != 'xls';
  160.  
  161. // Do we need to convert charset?
  162. $output_charset_conversion = $asfile &&
  163.     $cfg['AllowAnywhereRecoding'] && $allow_recoding
  164.     && isset($charset_of_file) && $charset_of_file != $charset
  165.     && $type != 'xls';
  166.  
  167. // Set whether we will need buffering
  168. $buffer_needed = isset($compression) && ($compression == 'zip' | $compression == 'gzip' | $compression == 'bzip');
  169.  
  170. // Use on fly compression?
  171. $onfly_compression = $GLOBALS['cfg']['CompressOnFly'] && isset($compression) && ($compression == 'gzip' | $compression == 'bzip');
  172. if ($onfly_compression) {
  173.     $memory_limit = trim(@ini_get('memory_limit'));
  174.     // 2 MB as default
  175.     if (empty($memory_limit)) {
  176.         $memory_limit = 2 * 1024 * 1024;
  177.     }
  178.  
  179.     if (strtolower(substr($memory_limit, -1)) == 'm') {
  180.         $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
  181.     } elseif (strtolower(substr($memory_limit, -1)) == 'k') {
  182.         $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
  183.     } elseif (strtolower(substr($memory_limit, -1)) == 'g') {
  184.         $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
  185.     } else {
  186.         $memory_limit = (int)$memory_limit;
  187.     }
  188.  
  189.     // Some of memory is needed for other thins and as treshold.
  190.     // Nijel: During export I had allocated (see memory_get_usage function)
  191.     //        approx 1.2MB so this comes from that.
  192.     if ($memory_limit > 1500000) {
  193.         $memory_limit -= 1500000;
  194.     }
  195.  
  196.     // Some memory is needed for compression, assume 1/3
  197.     $memory_limit *= 2/3;
  198. }
  199.  
  200. // Generate filename and mime type if needed
  201. if ($asfile) {
  202.     $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
  203.     if ($export_type == 'server') {
  204.         if (isset($remember_template)) {
  205.             setcookie('pma_server_filename_template', $filename_template, 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']);
  206.         }
  207.         $filename = str_replace('__SERVER__', $GLOBALS['cfg']['Server']['host'], strftime($filename_template));
  208.     } elseif ($export_type == 'database') {
  209.         if (isset($remember_template)) {
  210.             setcookie('pma_db_filename_template', $filename_template, 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']);
  211.         }
  212.         $filename = str_replace('__DB__', $db, str_replace('__SERVER__', $GLOBALS['cfg']['Server']['host'], strftime($filename_template)));
  213.     } else {
  214.         if (isset($remember_template)) {
  215.             setcookie('pma_table_filename_template', $filename_template, 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']);
  216.         }
  217.         $filename = str_replace('__TABLE__', $table, str_replace('__DB__', $db, str_replace('__SERVER__', $GLOBALS['cfg']['Server']['host'], strftime($filename_template))));
  218.     }
  219.  
  220.     // convert filename to iso-8859-1, it is safer
  221.     if (!(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) {
  222.         $filename = PMA_convert_string($charset, 'iso-8859-1', $filename);
  223.     } else {
  224.         $filename = PMA_convert_string($convcharset, 'iso-8859-1', $filename);
  225.     }
  226.  
  227.     // Generate basic dump extension
  228.     if ($type == 'csv') {
  229.         $filename  .= '.csv';
  230.         $mime_type = 'text/comma-separated-values';
  231.     } elseif ($type == 'htmlexcel') {
  232.         $filename  .= '.xls';
  233.         $mime_type = 'application/vnd.ms-excel';
  234.     } elseif ($type == 'htmlword') {
  235.         $filename  .= '.doc';
  236.         $mime_type = 'application/vnd.ms-word';
  237.     } elseif ($type == 'xls') {
  238.         $filename  .= '.xls';
  239.         $mime_type = 'application/vnd.ms-excel';
  240.     } elseif ($type == 'xml') {
  241.         $filename  .= '.xml';
  242.         $mime_type = 'text/xml';
  243.     } elseif ($type == 'latex') {
  244.         $filename  .= '.tex';
  245.         $mime_type = 'application/x-tex';
  246.     } elseif ($type == 'pdf') {
  247.         $filename  .= '.pdf';
  248.         $mime_type = 'application/pdf';
  249.     } else {
  250.         $filename  .= '.sql';
  251.         // text/x-sql is correct MIME type, however safari ignores further
  252.         // Content-Disposition header, so we must force it to download it this
  253.         // way...
  254.         $mime_type = PMA_USR_BROWSER_AGENT == 'SAFARI'
  255.                         ? 'application/octet-stream'
  256.                         : 'text/x-sql';
  257.     }
  258.  
  259.     // If dump is going to be compressed, set correct encoding or mime_type and add
  260.     // compression to extension
  261.     $content_encoding = '';
  262.     if (isset($compression) && $compression == 'bzip') {
  263.         $filename  .= '.bz2';
  264.         // browsers don't like this:
  265.         //$content_encoding = 'x-bzip2';
  266.         $mime_type = 'application/x-bzip2';
  267.     } elseif (isset($compression) && $compression == 'gzip') {
  268.         $filename  .= '.gz';
  269.         // Needed to avoid recompression by server modules like mod_gzip.
  270.         // It seems necessary to check about zlib.output_compression
  271.         // to avoid compressing twice
  272.         if (!@ini_get('zlib.output_compression')) {
  273.             $content_encoding = 'x-gzip';
  274.             $mime_type = 'application/x-gzip';
  275.         }
  276.     } elseif (isset($compression) && $compression == 'zip') {
  277.         $filename  .= '.zip';
  278.         $mime_type = 'application/zip';
  279.     }
  280. }
  281.  
  282. // Open file on server if needed
  283. if ($save_on_server) {
  284.     $save_filename = PMA_userDir($cfg['SaveDir']) . preg_replace('@[/\\\\]@', '_', $filename);
  285.     unset($message);
  286.     if (file_exists($save_filename) && empty($onserverover)) {
  287.         $message = sprintf($strFileAlreadyExists, htmlspecialchars($save_filename));
  288.         $GLOBALS['show_error_header'] = TRUE;
  289.     } else {
  290.         if (is_file($save_filename) && !is_writable($save_filename)) {
  291.             $message = sprintf($strNoPermission, htmlspecialchars($save_filename));
  292.             $GLOBALS['show_error_header'] = TRUE;
  293.         } else {
  294.             if (!$file_handle = @fopen($save_filename, 'w')) {
  295.                 $message = sprintf($strNoPermission, htmlspecialchars($save_filename));
  296.                 $GLOBALS['show_error_header'] = TRUE;
  297.             }
  298.         }
  299.     }
  300.     if (isset($message)) {
  301.         $js_to_run = 'functions.js';
  302.         require_once('./libraries/header.inc.php');
  303.         if ($export_type == 'server') {
  304.             $active_page = 'server_export.php';
  305.             require('./server_export.php');
  306.         } elseif ($export_type == 'database') {
  307.             $active_page = 'db_details_export.php';
  308.             require('./db_details_export.php');
  309.         } else {
  310.             $active_page = 'tbl_properties_export.php';
  311.             require('./tbl_properties_export.php');
  312.         }
  313.         exit();
  314.     }
  315. }
  316.  
  317. /**
  318.  * Send headers depending on whether the user chose to download a dump file
  319.  * or not
  320.  */
  321. if (!$save_on_server) {
  322.     if ($asfile ) {
  323.         // Download
  324.         if (!empty($content_encoding)) {
  325.             header('Content-Encoding: ' . $content_encoding);
  326.         }
  327.         header('Content-Type: ' . $mime_type);
  328.         header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  329.         // lem9: Tested behavior of
  330.         //       IE 5.50.4807.2300
  331.         //       IE 6.0.2800.1106 (small glitch, asks twice when I click Open)
  332.         //       IE 6.0.2900.2180
  333.         //       Firefox 1.0.6
  334.         // in http and https
  335.         header('Content-Disposition: attachment; filename="' . $filename . '"');
  336.         if (PMA_USR_BROWSER_AGENT == 'IE') {
  337.             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  338.             header('Pragma: public');
  339.         } else {
  340.             header('Pragma: no-cache');
  341.         }
  342.     } else {
  343.         // HTML
  344.         $backup_cfgServer = $cfg['Server'];
  345.         require_once('./libraries/header.inc.php');
  346.         $cfg['Server'] = $backup_cfgServer;
  347.         unset($backup_cfgServer);
  348.         echo "\n" . '<div align="' . $cell_align_left . '">' . "\n";
  349.         //echo '    <pre>' . "\n";
  350.         echo '    <form name="nofunction">' . "\n"
  351.            // remove auto-select for now: there is no way to select
  352.            // only a part of the text; anyway, it should obey
  353.            // $cfg['TextareaAutoSelect']
  354.            //. '        <textarea name="sqldump" cols="50" rows="30" onclick="this.select();" id="textSQLDUMP" wrap="OFF">' . "\n";
  355.            . '        <textarea name="sqldump" cols="50" rows="30" id="textSQLDUMP" wrap="OFF">' . "\n";
  356.     } // end download
  357. }
  358.  
  359. // Check if we have something to export
  360. if ($export_type == 'database') {
  361.     $tables     = PMA_DBI_get_tables($db);
  362.     $num_tables = count($tables);
  363.     if ($num_tables == 0) {
  364.         $message = $strNoTablesFound;
  365.         $js_to_run = 'functions.js';
  366.         require_once('./libraries/header.inc.php');
  367.         if ($export_type == 'server') {
  368.             $active_page = 'server_export.php';
  369.             require('./server_export.php');
  370.         } elseif ($export_type == 'database') {
  371.             $active_page = 'db_details_export.php';
  372.             require('./db_details_export.php');
  373.         } else {
  374.             $active_page = 'tbl_properties_export.php';
  375.             require('./tbl_properties_export.php');
  376.         }
  377.         exit();
  378.     }
  379. }
  380.  
  381. // Fake loop just to allow skip of remain of this code by break, I'd really
  382. // need exceptions here :-)
  383. do {
  384.  
  385. // Add possibly some comments to export
  386. if (!PMA_exportHeader()) {
  387.     break;
  388. }
  389.  
  390. // Will we need relation & co. setup?
  391. $do_relation = isset($GLOBALS[$what . '_relation']);
  392. $do_comments = isset($GLOBALS[$what . '_comments']);
  393. $do_mime     = isset($GLOBALS[$what . '_mime']);
  394. if ($do_relation || $do_comments || $do_mime) {
  395.     require_once('./libraries/relation.lib.php');
  396.     $cfgRelation = PMA_getRelationsParam();
  397. }
  398. if ($do_mime) {
  399.     require_once('./libraries/transformations.lib.php');
  400. }
  401.  
  402. // Include dates in export?
  403. $do_dates   = isset($GLOBALS[$what . '_dates']);
  404.  
  405. /**
  406.  * Builds the dump
  407.  */
  408. // Gets the number of tables if a dump of a database has been required
  409. if ($export_type == 'server') {
  410.     /**
  411.      * Gets the databases list - if it has not been built yet
  412.      */
  413.     if ($server > 0 && empty($dblist)) {
  414.         PMA_availableDatabases();
  415.     }
  416.  
  417.     if (isset($db_select)) {
  418.         $tmp_select = implode($db_select, '|');
  419.         $tmp_select = '|' . $tmp_select . '|';
  420.     }
  421.     // Walk over databases
  422.     foreach ($dblist AS $current_db) {
  423.         if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))
  424.             || !isset($tmp_select)) {
  425.             if (!PMA_exportDBHeader($current_db)) {
  426.                 break 2;
  427.             }
  428.             if (!PMA_exportDBCreate($current_db)) {
  429.                 break 2;
  430.             }
  431.             $tables = PMA_DBI_get_tables($current_db);
  432.             $views = array();
  433.             foreach ($tables as $table) {
  434.                 // if this is a view, collect it for later; views must be exported
  435.                 // after the tables
  436.                 if (PMA_tableIsView($current_db, $table)) {
  437.                     $views[] = $table;
  438.                     continue;
  439.                 }
  440.                 $local_query  = 'SELECT * FROM ' . PMA_backquote($current_db) . '.' . PMA_backquote($table);
  441.                 if (isset($GLOBALS[$what . '_structure'])) {
  442.                     if (!PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) {
  443.                         break 3;
  444.                     }
  445.                 }
  446.                 if (isset($GLOBALS[$what . '_data'])) {
  447.                     if (!PMA_exportData($current_db, $table, $crlf, $err_url, $local_query)) {
  448.                         break 3;
  449.                     }
  450.                 }
  451.             }
  452.             foreach($views as $view) {
  453.                 // no data export for a view
  454.                 if (isset($GLOBALS[$what . '_structure'])) {
  455.                     if (!PMA_exportStructure($current_db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) {
  456.                         break 3;
  457.                     }
  458.                 }
  459.             }
  460.             if (!PMA_exportDBFooter($current_db)) {
  461.                 break 2;
  462.             }
  463.         }
  464.     }
  465. } elseif ($export_type == 'database') {
  466.     if (!PMA_exportDBHeader($db)) {
  467.         break;
  468.     }
  469.  
  470.     if (isset($table_select)) {
  471.         $tmp_select = implode($table_select, '|');
  472.         $tmp_select = '|' . $tmp_select . '|';
  473.     }
  474.     $i = 0;
  475.     $views = array();
  476.     foreach ($tables as $table) {
  477.         // if this is a view, collect it for later; views must be exported after
  478.         // the tables
  479.         if (PMA_tableIsView($db, $table)) {
  480.             $views[] = $table;
  481.             continue;
  482.         }
  483.         $local_query  = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
  484.         if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $table . '|'))
  485.             || !isset($tmp_select)) {
  486.  
  487.             if (isset($GLOBALS[$what . '_structure'])) {
  488.                 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) {
  489.                     break 2;
  490.                 }
  491.             }
  492.             if (isset($GLOBALS[$what . '_data'])) {
  493.                 if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
  494.                     break 2;
  495.                 }
  496.             }
  497.         }
  498.     }
  499.     foreach ($views as $view) {
  500.         // no data export for a view
  501.         if (isset($GLOBALS[$what . '_structure'])) {
  502.             if (!PMA_exportStructure($db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) {
  503.                 break 2;
  504.             }
  505.         }
  506.     }
  507.     if (!PMA_exportDBFooter($db)) {
  508.         break;
  509.     }
  510. } else {
  511.     if (!PMA_exportDBHeader($db)) {
  512.         break;
  513.     }
  514.     // We export just one table
  515.  
  516.     if ($limit_to > 0 && $limit_from >= 0) {
  517.         $add_query  = ' LIMIT '
  518.                     . (($limit_from > 0) ? $limit_from . ', ' : '')
  519.                     . $limit_to;
  520.     } else {
  521.         $add_query  = '';
  522.     }
  523.  
  524.     if (!empty($sql_query)) {
  525.         // only preg_replace if needed
  526.         if (!empty($add_query)) {
  527.             // remove trailing semicolon before adding a LIMIT
  528.             $sql_query = preg_replace('%;\s*$%', '', $sql_query);
  529.         }
  530.         $local_query = $sql_query . $add_query;
  531.         PMA_DBI_select_db($db);
  532.     } else {
  533.         $local_query  = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query;
  534.     }
  535.  
  536.     if (isset($GLOBALS[$what . '_structure'])) {
  537.         if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) {
  538.             break;
  539.         }
  540.     }
  541.     // I think we have to export data for a single view; for example PDF report
  542.     if (isset($GLOBALS[$what . '_data'])) {
  543.         if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
  544.             break;
  545.         }
  546.     }
  547.     if (!PMA_exportDBFooter($db)) {
  548.         break;
  549.     }
  550. }
  551. if (!PMA_exportFooter()) {
  552.     break;
  553. }
  554.  
  555. } while (FALSE);
  556. // End of fake loop
  557.  
  558. if ($save_on_server && isset($message)) {
  559.     $js_to_run = 'functions.js';
  560.     require_once('./libraries/header.inc.php');
  561.     if ($export_type == 'server') {
  562.         $active_page = 'server_export.php';
  563.         require('./server_export.php');
  564.     } elseif ($export_type == 'database') {
  565.         $active_page = 'db_details_export.php';
  566.         require('./db_details_export.php');
  567.     } else {
  568.         $active_page = 'tbl_properties_export.php';
  569.         require('./tbl_properties_export.php');
  570.     }
  571.     exit();
  572. }
  573.  
  574. /**
  575.  * Send the dump as a file...
  576.  */
  577. if (!empty($asfile)) {
  578.     // Convert the charset if required.
  579.     if ($output_charset_conversion) {
  580.         $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer);
  581.     }
  582.  
  583.     // Do the compression
  584.     // 1. as a gzipped file
  585.     if (isset($compression) && $compression == 'zip') {
  586.         if (@function_exists('gzcompress')) {
  587.             $zipfile = new zipfile();
  588.             $zipfile -> addFile($dump_buffer, substr($filename, 0, -4));
  589.             $dump_buffer = $zipfile -> file();
  590.         }
  591.     }
  592.     // 2. as a bzipped file
  593.     elseif (isset($compression) && $compression == 'bzip') {
  594.         if (@function_exists('bzcompress')) {
  595.             $dump_buffer = bzcompress($dump_buffer);
  596.             if ($dump_buffer === -8) {
  597.                 require_once('./libraries/header.inc.php');
  598.                 echo sprintf($strBzError, '<a href="http://bugs.php.net/bug.php?id=17300" target="_blank">17300</a>');
  599.                 require_once('./libraries/footer.inc.php');
  600.             }
  601.         }
  602.     }
  603.     // 3. as a gzipped file
  604.     elseif (isset($compression) && $compression == 'gzip') {
  605.         if (@function_exists('gzencode')) {
  606.             // without the optional parameter level because it bug
  607.             $dump_buffer = gzencode($dump_buffer);
  608.         }
  609.     }
  610.  
  611.     /* If ve saved on server, we have to close file now */
  612.     if ($save_on_server) {
  613.         $write_result = @fwrite($file_handle, $dump_buffer);
  614.         fclose($file_handle);
  615.         if (strlen($dump_buffer) !=0 && (!$write_result || ($write_result != strlen($dump_buffer)))) {
  616.             $message = sprintf($strNoSpace, htmlspecialchars($save_filename));
  617.         } else {
  618.             $message = sprintf($strDumpSaved, htmlspecialchars($save_filename));
  619.         }
  620.  
  621.         $js_to_run = 'functions.js';
  622.         require_once('./libraries/header.inc.php');
  623.         if ($export_type == 'server') {
  624.             $active_page = 'server_export.php';
  625.             require_once('./server_export.php');
  626.         } elseif ($export_type == 'database') {
  627.             $active_page = 'db_details_export.php';
  628.             require_once('./db_details_export.php');
  629.         } else {
  630.             $active_page = 'tbl_properties_export.php';
  631.             require_once('./tbl_properties_export.php');
  632.         }
  633.         exit();
  634.     } else {
  635.         echo $dump_buffer;
  636.     }
  637. }
  638. /**
  639.  * Displays the dump...
  640.  */
  641. else {
  642.     /**
  643.      * Close the html tags and add the footers in dump is displayed on screen
  644.      */
  645.     //echo '    </pre>' . "\n";
  646.     echo '</textarea>' . "\n"
  647.        . '    </form>' . "\n";
  648.     echo '</div>' . "\n";
  649.     echo "\n";
  650. ?>
  651. <script type="text/javascript" language="javascript">
  652. //<![CDATA[
  653.     var bodyWidth=null; var bodyHeight=null;
  654.     if (document.getElementById('textSQLDUMP')) {
  655.         bodyWidth  = self.innerWidth;
  656.         bodyHeight = self.innerHeight;
  657.         if (!bodyWidth && !bodyHeight) {
  658.             if (document.compatMode && document.compatMode == "BackCompat") {
  659.                 bodyWidth  = document.body.clientWidth;
  660.                 bodyHeight = document.body.clientHeight;
  661.             } else if (document.compatMode && document.compatMode == "CSS1Compat") {
  662.                 bodyWidth  = document.documentElement.clientWidth;
  663.                 bodyHeight = document.documentElement.clientHeight;
  664.             }
  665.         }
  666.         document.getElementById('textSQLDUMP').style.width=(bodyWidth-50) + 'px';
  667.         document.getElementById('textSQLDUMP').style.height=(bodyHeight-100) + 'px';
  668.     }
  669. //]]>
  670. </script>
  671. <?php
  672.     require_once('./libraries/footer.inc.php');
  673. } // end if
  674. ?>
  675.